//localStorage 本地存储
//

var GLOBAL_SESSION = 'ADMIN_SY_CHARITY';

!window.LOCAL_STORE && (window.LOCAL_STORE = {});
// context 对象
window.LOCAL_STORE.context = {
    session: {options: {}},
    params: {
        put: function (key, value) {
            !LOCAL_STORE.context.params.data && (LOCAL_STORE.context.params.data = {});
            if (typeof key == 'string') {
                LOCAL_STORE.context.params.data[key] = value;
            } else {
                angular.extend(LOCAL_STORE.context.params.data, key);
            }
            return this;
        },
        get: function (key) {
            !LOCAL_STORE.context.params.data && (LOCAL_STORE.context.params.data = {});
            return LOCAL_STORE.context.params.data[key];
        },
        take: function (key) {
            var value = LOCAL_STORE.context.params.get(key);
            delete LOCAL_STORE.context.params.data[key];
            return value;
        },
        remove: function (key) {
            delete LOCAL_STORE.context.params.data[key];
        }
    },
    rme: function (name) {
        LOCAL_STORE.context.session && (window.localStorage[name] = angular.toJson(LOCAL_STORE.context.session));
        return this;
    },
    dme: function (name) {
        delete window.localStorage[name];
    },
    open: function (name) {
        var session = window.localStorage[name];
        session && (LOCAL_STORE.context.session = angular.fromJson(session));
        return this;
    },
    close: function () {
        LOCAL_STORE.context.session = {};
        LOCAL_STORE.context.params.data = {};
        return this;
    }
};
